package com.logos.musicframe.utils;

import java.util.prefs.Preferences;

/**
 * @author logos
 * date 2025/6/02 14:55
 * @version v1.0
 * @Package com.logos.musicframe.utils
 */
public class LocalSessionStorageUtil {

    private static final String USER_TOKEN_KEY = "user_token";
    private static final String USER_ID_KEY = "user_id";
    private static final Preferences prefs = Preferences.userNodeForPackage(LocalSessionStorageUtil.class);

    // 保存登录信息到本地
    public static void saveLoginSession(String userId, String token) {
        prefs.put(USER_ID_KEY, userId);
        prefs.put(USER_TOKEN_KEY, token);
    }

    // 获取本地保存的登录信息
    public static String[] getLoginSession() {
        String userId = prefs.get(USER_ID_KEY, null);
        String token = prefs.get(USER_TOKEN_KEY, null);
        return new String[]{userId, token};
    }

    // 清除登录信息
    public static void clearLoginSession() {
        try {
            prefs.remove(USER_ID_KEY);
            prefs.remove(USER_TOKEN_KEY);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
